<?php
/**
 * Created by PhpStorm.
 * User: huangpeng3
 * Date: 2018/1/5
 * Time: 下午2:08
 * 用户注册模型
 */

namespace Home\Model;

use Think\Model;

class RegModel extends Model
{

    protected $tableName = 'coin_user_info';


    /**
     * @param $username
     * @param $password
     */
    public function register($username, $password)
    {
        $rtn = array();
        $user_type = 'phone';
        $data[$user_type] = $username;
        $data['password'] = md5($password . 'coinmd5');
        if (!self::exists($username)) {
            if ($this->add($data)) {
                $rtn['status'] = true;
                $rtn['info'] = '注册成功,请点击快速登录';
            } else {
                $rtn['status'] = false;
                $rtn['info'] = '注册失败,请一段时间后再试';
            }
        } else {
            $rtn['status'] = false;
            $rtn['info'] = '用户名已被注册';
        }
        return $rtn;
    }

    /**
     * @param $username
     */
    public function exists($username)
    {
        $user_type = 'phone';
        $map[$user_type] = $username;
        $arr = $this->where($map)->select();
        if (!empty($arr)) {
            return true;
        } else {
            return false;
        }
    }
}
